<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* 
        await语句后所有的代码都变成异步代码
        await只能等promise实例,其他一概不等
        */
        async function grn() {
            /* console.log('start');
            await setTimeout(() => {
                console.log('计时器');
            }, 1000);
            console.log('计数器后面的语句'); */

            console.log('start');
            await new Promise((resolve,reject) => {
                setTimeout(() => {
                    console.log('计时器');
                    //当promise内部的异步代码执行完成,我们修改promise的状态,await就能收到完成信息了
                    resolve()
                }, 1000);
                
            });
            console.log('计数器后面的语句');

        }
        grn()
        console.log('end');
    </script>
</body>

</html>